package ar.edu.itba.it.paw.domain;



public class User extends PersistentAttributes {
	
	private String username;
	private String password;
	private String first_name;
	private String last_name;
	private String mail;
	private boolean admin;
	
	//This constructor is used to create users before they are inserted to the database
	public User(String username, String password, String first_name, String last_name, String mail) throws IllegalArgumentException{
		if(!(username == null || username.equals("") || password == null || password.equals("") || first_name == null || first_name.equals("") || last_name == null || last_name.equals("") || mail == null || mail.equals("")
				|| username.length() > 20 || password.length() < 8)){
				this.setUsername(username);
				this.setPassword(password);
				this.setFirst_name(first_name);
				this.setLast_name(last_name);
				this.setMail(mail);
		}
		else{
			throw new IllegalArgumentException();
		}
	}
	//This constructor is used to obtain users from the database
	public User(String username, String password, String nombre, String apellido, String mail, int user_id, boolean admin) throws IllegalArgumentException{
		this(username,password,nombre,apellido,mail);
		if(user_id < 0){
			throw new IllegalArgumentException("Invalid User Id");
		}
		this.setId(user_id);
		this.setAdmin(admin);
	}
	
	public void setUsername(String username) {
		this.username = username;
	}

	public String getUsername() {
		return username;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPassword() {
		return password;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public String getMail() {
		return mail;
	}
	
	public String getFirst_name() {
		return first_name;
	}
	
	public void setFirst_name(String first_name) {
		this.first_name = first_name;
	}
	
	public String getLast_name() {
		return last_name;
	}
	
	public void setLast_name(String last_name) {
		this.last_name = last_name;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((username == null) ? 0 : username.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (username == null) {
			if (other.username != null)
				return false;
		} else if (!username.equals(other.username))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return "User [username=" + username + ", password=" + password
				+ ", nombre=" + first_name + ", apellido=" + last_name + ", mail="
				+ mail + ", userId=" + getId() + "]";
	}
	public void setAdmin(boolean admin) {
		this.admin = admin;
	}
	public boolean isAdmin() {
		return admin;
	}

}
